package com.buka.communicate.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.adapter.ImpressTagAdapter;
import com.buka.communicate.adapter.TagAdapter;
import com.buka.communicate.adapter.TagAdapter_;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.neiquan.applibrary.base.BaseActivity;
import net.neiquan.applibrary.flowtag.FlowTagLayout;
import net.neiquan.applibrary.flowtag.OnTagSelectListener;
import net.neiquan.applibrary.numberpicker.view.AlertDatePicker;
import net.neiquan.applibrary.wight.AlertChooser;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/13 0013.
 */

public class InfoEditActivity extends BaseActivity {
    @InjectView(R.id.mHeadImg)
    SimpleDraweeView mHeadImg;
    @InjectView(R.id.mHeadRv)
    RelativeLayout mHeadRv;
    @InjectView(R.id.nickTv)
    TextView nickTv;
    @InjectView(R.id.mNickName)
    EditText mNickName;
    @InjectView(R.id.mAgeTv)
    TextView mAgeTv;
    @InjectView(R.id.mAgeRv)
    RelativeLayout mAgeRv;
    @InjectView(R.id.jobTv)
    TextView jobTv;
    @InjectView(R.id.mJobTv)
    TextView mJobTv;
    @InjectView(R.id.mJobRv)
    RelativeLayout mJobRv;
    @InjectView(R.id.mTagRv)
    RelativeLayout mTagRv;
    @InjectView(R.id.mSignEt)
    EditText mSignEt;
    @InjectView(R.id.mHobbyEt)
    EditText mHobbyEt;
    @InjectView(R.id.mTagFlowLayout)
    FlowTagLayout mTagFlowLayout;
    private TagAdapter_<String> adapter;

    @Override
    public int getRootViewId() {
        return R.layout.activity_info_edit;
    }

    @Override
    public void setViews() {
        setTitleTv("编辑资料");
        setNextTv("保存");
        getNextTv().setTextColor(getResources().getColor(R.color.app_color));
    }

    @Override
    public void initData() {
        mHeadImg.setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
        initTagRecylerView();
    }

    private void initTagRecylerView() {
        List<String> strings = new ArrayList<>();
        strings.add("白领");
//        strings.add("宇宙第一帅");
//        strings.add("文艺");
//        strings.add("极品吃货");
//        strings.add("萌萌哒");
//        strings.add("萌萌哒");
//        strings.add("萌萌哒");
//        strings.add("萌萌哒");
        strings.add("+添加印象");
        mTagFlowLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_SINGLE);
        adapter = new TagAdapter_<String>(this);
        mTagFlowLayout.setAdapter(adapter);
        adapter.clearAndAddAll(strings);
        mTagFlowLayout.setOnTagSelectListener(new OnTagSelectListener() {
            @Override
            public void onItemSelect(FlowTagLayout parent, List<Integer> selectedList) {
                startActivity(new Intent(InfoEditActivity.this,ImpressTagActivity.class));
//                for (int i = 0; i < selectedList.size(); i++) {
//                    AppLog.e("==========setOnTagSelectListener===========" + selectedList.get(i));
//                    Search data = ((Search) parent.getAdapter().getItem(selectedList.get(i)));
//                    Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
//                    intent.putExtra("search", data.getTitle());
//                    startActivity(intent);
//                }
            }
        });
    }

    @OnClick({R.id.mHeadRv, R.id.mAgeRv, R.id.mJobRv, R.id.mTagRv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.mHeadRv:
                showAlertChooser();
                break;
            case R.id.mAgeRv:
                new AlertDatePicker.Builder(InfoEditActivity.this)
                        .setTitle("请选择您的出生日期")
                        .setCancelable(true)
                        .setDateSelectListener(new AlertDatePicker.OnDateSelectListener() {
                            @Override
                            public void endSelect(Date selectDate, String selectDateStr, boolean isCancel) {
                                mAgeTv.setText(selectDateStr);
                            }
                        }).show();
                break;
            case R.id.mJobRv:
                startActivity(new Intent(InfoEditActivity.this,WorkTagActivity.class));
                break;
            case R.id.mTagRv:
                startActivity(new Intent(InfoEditActivity.this,ImpressTagActivity.class));
                break;
        }
    }

    private void showAlertChooser() {
        new AlertChooser.Builder(this).setTitle("选择图片").addItem("相机", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).addItem("相册", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).setNegativeItem("取消", new AlertChooser.OnItemClickListener() {
            @Override
            public void OnItemClick(AlertChooser chooser) {
                chooser.dismiss();
            }
        }).show();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }
}
